<template>
	<view class="boos">
		<view class="content" v-for="(item , index) in categoryItemList" :key="index">
			<view class="title-1">{{item.category.name}}</view>
			<view class="title-2">{{item.category.name}}</view>
			<view class="item-out-box">
				<view class="item" v-for="(ele,numb) in item.itemList" :key="numb" @click="goToDetail(item.itemList , ele.id)">
					<!-- 主图 -->
					<image class="img-pic" :src="ele.listPicUrl" mode=""></image>
					<view class="info">
						<view class="one">
							<!-- 自营 小图片 -->
							<image v-if="ele.preLogo.length != 0" class="img-logo" v-for="(pc,mb) in ele.preLogo"
								:key="mb" :src="pc.logoUrl" mode="">
							</image>
							<text class="one-txt" :style="{marginLeft:ele.preLogo.length != 0?'':0}">{{ele.name}}</text>
						</view>
						<!-- 可用红包 -->
						<template v-if="ele.itemTagList.length!=0">
							<view class="use-hb" v-for="(hb,m) in ele.itemTagList" :key="m">
								<i class="iconfont icon-hongbao1"></i><text>{{hb.name}}</text>
							</view>
							<view class="two">
								<template v-if="ele.finalPriceInfoVO.priceInfo.finalPrice != null">
									<text
										class="two-1">{{ele.finalPriceInfoVO.priceInfo.finalPrice.prefix}}￥</text><text
										class="two-2">{{ele.finalPriceInfoVO.priceInfo.finalPrice.price}}</text><text
										class="two-3">￥{{ele.finalPriceInfoVO.priceInfo.counterPrice}}</text>
								</template>
								<template v-else>
									<text class="two-1">￥</text>
									<text class="two-2">{{ele.finalPriceInfoVO.priceInfo.basicPrice}}</text>
								</template>

							</view>
							<view class="manjan" v-if="ele.finalPriceInfoVO.banner != null">
								{{ele.finalPriceInfoVO.banner.content}}
							</view>
						</template>
						<!-- 没有红包 -->
						<template v-else>
							<view class="two">
								<text class="two-1">￥</text>
								<template v-if="ele.finalPriceInfoVO.priceInfo.finalPrice != null">
									<text class="two-2">{{ele.finalPriceInfoVO.priceInfo.finalPrice.price}}</text>
									<text class="two-3">￥{{ele.finalPriceInfoVO.priceInfo.counterPrice}}</text>
								</template>
								<template v-else>
									<text class="two-2">{{ele.finalPriceInfoVO.priceInfo.basicPrice}}</text>
								</template>
							</view>
							<view class="three" v-if="ele.finalPriceInfoVO.banner != null">
								<text class="three-1">{{ele.finalPriceInfoVO.banner.title}}</text><text
									class="three-2">{{ele.finalPriceInfoVO.banner.content}}</text>
							</view>
						</template>

					</view>
					<view v-if="ele.colorNum!=0" class="color-num">{{ele.colorNum}}色可选</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "cateCompt",
		props: {
			categoryId: {
				type: String,
				default: ''
			}
		},
		data() {
			return {
				categoryItemList: []
			};
		},
		watch: {
			categoryId: {
				handler(nd, od) {
					this.getCateData(nd)
				},
				immediate: true, //立即监听
				deep: true, // 深度监听
			}
		},
		methods: {
			async getCateData(nd) {
				// 方法1 使用vue的全局
				// let res = await this.$request(this.$base.itemsData, "GET", {
				// 	categoryId: nd
				// })
				// 方法2 使用uni的全局
				let res = await uni.$request(uni.$base.itemsData, "GET", {
					categoryId: nd
				})
				this.categoryItemList = res.data.categoryItemList
				this.$emit('changeTabName', res.data.categoryList)
			},
			// 跳转到详情页
			goToDetail(itemList,id){
				uni.navigateTo({
					url:"../../pages/detail/detail?itemList=" + JSON.stringify(itemList) +"&id=" + id
				})
			}
		}

	}
</script>

<style lang="less">
	.boos {
		width: 100%;
		height: 100%;
		background: #eee;

		.content {
			background-color: #fff;
			padding: 20rpx;
			margin-bottom: 18rpx;

			.title-1 {
				font-size: 32rpx;
				text-align: center;
			}

			.title-2 {
				text-align: center;
				font-size: 24rpx;
				color: #999;
				margin: 10rpx 0;
			}

			.item-out-box {
				display: flex;
				flex-wrap: wrap;
				justify-content: space-between;

				.item {
					width: 345rpx;
					position: relative;
					margin-bottom: 40rpx;

					.img-pic {
						width: 345rpx;
						height: 345rpx;
						border-radius: 10rpx;
					}

					.info {
						width: 345rpx;

						.one {
							height: 80rpx;
							position: relative;
							font-size: 28rpx;
							text-align: left;

							.img-logo {
								width: 48rpx;
								height: 30rpx;
								position: absolute;
								left: 0;
								top: 4rpx;
							}

							.one-txt {
								margin-left: 53rpx;
							}
						}

						.use-hb {
							padding: 0 4rpx;
							text-align: center;
							height: 40rpx;
							font-size: 20rpx;
							width: 112rpx;
							border-radius: 20rpx;
							display: flex;
							align-items: center;
							border: 2rpx solid #b6aeae;

							i {
								position: relative;
								top: 6rpx;
								color: #fa1e32;
							}
						}

						.manjan {
							width: 126rpx;
							height: 38rpx;
							font-size: 22rpx;
							text-align: center;
							border-radius: 20rpx;
							background-color: #fa1e32;
							color: #fff;
							line-height: 38rpx;
							padding: 0 4rpx;
						}

						.two {
							font-weight: bold;
							color: #ff0000;
							margin: 5rpx 0 10rpx 0;

							.two-1 {
								font-size: 20rpx;
							}

							.two-2 {
								font-size: 32rpx;
								margin: 0 4rpx;
							}

							.two-3 {
								font-size: 20rpx;
								color: #999;
								text-decoration: line-through;
							}
						}

						.three {
							background-color: #ffe9eb;
							height: 38rpx;
							line-height: 38rpx;
							color: #ff0000;
							font-size: 20rpx;
							font-weight: bold;
							border-radius: 20rpx;
							white-space: nowrap;
							padding: 4rpx;

							.three-1 {
								display: inline-block;
								width: 96rpx;
								height: 38rpx;
								text-align: center;
								border-radius: 20rpx;
								background-color: #fa1e32;
								color: #fff;
								margin-right: 10rpx;
							}
						}
					}

					.color-num {
						font-size: 20rpx;
						text-align: center;
						padding: 6rpx 0 2rpx;
						width: 30rpx;
						border: 2rpx solid #333;
						background-color: #f4f4f4;
						position: absolute;
						top: 8rpx;
						left: 6rpx;
					}
				}
			}
		}
	}
</style>